<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends CIC_A_Controller
{
	function __construct()
	{
		parent::__construct();
	}	
	function index()
	{
		$data	= $this->get_user();
		$this->load->view('admin/user/index',$data);
	}
	
	function content_add()
	{
		$this->load->view('admin/user/content_add');
	}
	
	function content_edit()
	{
		$data = array(
				'ckeditor_config'	=> $this->ckeditor_config,
				'user'			=> $this->cic_model->get_one('user',array('user_id'=>$this->uri->segment(4))),
		);
		$this->load->view('admin/user/content_edit',$data);
	}
	function add_content()
	{
		$this->validate('user', 'admin/user/content_add');
		$data = array(
				'user_name'			=> $this->input->post('user_name'),
				'user_password'		=> md5($this->input->post('user_password')),
				'user_status'		=> $this->input->post('user_status'),
				'user_register_time'=> time(),	
		);
		if($this->cic_model->insert('user',$data))
		{
			$this->message->msg('添加成功！',site_url('admin/user/index'));
		}else{
			$this->message->msg('添加失败！',site_url('admin/user/content_add'));
		}
	}
	
	function edit_content()
	{	
		$data = array(
				'user_name'			=> $this->input->post('user_name'),
				'user_status'		=> $this->input->post('user_status'),
		);
		if($this->input->post('user_password') != '')
		{
			$data['user_password'] = md5($this->input->post('user_password'));
		}
		if($this->cic_model->update('user',$data,array('user_id'=>$this->uri->segment(4))))
		{
			$this->message->msg('修改成功！',site_url('admin/user/index'));
		}else{
			$this->message->msg('未做任何修改！',site_url('admin/user/content_edit/'.$this->uri->segment(4)));
		}
	}
	
	function get_user()
	{
		$where	= '';
		$and 	= '';
		$url = site_url('admin/user/index?');
		$data['page']	 = $this->page($url, $this->cic_model->get_total_rows('user'), $this->per_page,TRUE);
		$data['user'] = $this->cic_model->get_all('user',$where,array('user_register_time','desc'),$this->per_page,$this->input->get('per_page'));
		return $data;
	}
	
	
	function delete_content()
	{
		if($this->cic_model->delete('user',array('user_id'=>$this->input->post('user_id'))))
		{
			echo 1;
		}else{
			echo 0;
		}
	}
}